home *** CD-ROM | disk | FTP | other *** search
/ Technotools / Technotools (Chestnut CD-ROM)(1993).ISO / lang_asm / as1 / do1.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-04-30  |  3.0 KB  |  160 lines

  1. /*
  2.  *      MC6801 specific processing
  3.  */
  4.  
  5. /* addressing modes */
  6. #define IMMED   0       /* immediate */
  7. #define IND     1       /* indexed */
  8. #define OTHER   2       /* NOTA */
  9.  
  10.  
  11. char *skip_white();   /* this line added to keep TurboC happy 4/30/88 jec */
  12.  
  13. /*
  14.  *      localinit --- machine specific initialization
  15.  */
  16. localinit()
  17. {
  18. }
  19.  
  20. /*
  21.  *      do_op --- process mnemonic
  22.  *
  23.  *    Called with the base opcode and it's class. Optr points to
  24.  *    the beginning of the operand field.
  25.  */
  26. do_op(opcode,class)
  27. int opcode;    /* base opcode */
  28. int class;    /* mnemonic class */
  29. {
  30.     int     dist;   /* relative branch distance */
  31.     int     amode;  /* indicated addressing mode */
  32.     char    *peek;
  33.  
  34.     /* guess at addressing mode */
  35.     peek = Optr;
  36.     amode = OTHER;
  37.     while( !delim(*peek) && *peek != EOS)  /* check for comma in operand field */
  38.         if( *peek++ == ',' ){
  39.             amode = IND;
  40.             break;
  41.             }
  42.     if( *Optr == '#' ) amode = IMMED;
  43.  
  44.     switch(class){
  45.         case INH:                       /* inherent addressing */
  46.             emit(opcode);
  47.             return;
  48.         case GEN:                       /* general addressing */
  49.             do_gen(opcode,amode);
  50.             return;
  51.         case REL:                       /* relative branches */
  52.             eval();
  53.             dist = Result - (Pc+2);
  54.             emit(opcode);
  55.             if( (dist >127 || dist <-128) && Pass==2){
  56.                 error("Branch out of Range");
  57.                 emit(lobyte(-2));
  58.                 return;
  59.                 }
  60.             emit(lobyte(dist));
  61.             return;
  62.         case NOIMM:
  63.             if( amode == IMMED){
  64.                 error("Immediate Addressing Illegal");
  65.                 return;
  66.                 }
  67.             do_gen(opcode,amode);
  68.             return;
  69.         case LONGIMM:
  70.             if( amode == IMMED ){
  71.                 emit(opcode);
  72.                 Optr++;
  73.                 eval();
  74.                 eword(Result);
  75.                 return;
  76.                 }
  77.             do_gen(opcode,amode);
  78.             return;
  79.         case GRP2:
  80.             if( amode == IND ){
  81.                 do_indexed(opcode);
  82.                 return;
  83.                 }
  84.             /* extended addressing */
  85.             eval();
  86.             emit(opcode+0x10);
  87.             eword(Result);
  88.             return;
  89.         default:
  90.             fatal("Error in Mnemonic table");
  91.         }
  92. }
  93.  
  94. /*
  95.  *      do_gen --- process general addressing modes
  96.  */
  97. do_gen(op,mode)
  98. int     op;
  99. int     mode;
  100. {
  101.     if( mode == IMMED){
  102.         Optr++;
  103.         emit(op);
  104.         eval();
  105.         emit(lobyte(Result));
  106.         return;
  107.         }
  108.     else if( mode == IND ){
  109.         Cycles+=2;
  110.         do_indexed(op+0x20);
  111.         return;
  112.         }
  113.     else if( mode == OTHER){
  114.         eval();
  115.         if(Force_word){
  116.             emit(op+0x30);
  117.             eword(Result);
  118.             Cycles+=2;
  119.             return;
  120.             }
  121.         if(Force_byte){
  122.             emit(op+0x10);
  123.             emit(lobyte(Result));
  124.             Cycles++;
  125.             return;
  126.             }
  127.         if(Result>=0 && Result <=0xFF){
  128.             emit(op+0x10);
  129.             emit(lobyte(Result));
  130.             Cycles++;
  131.             return;
  132.             }
  133.         else {
  134.             emit(op+0x30);
  135.             eword(Result);
  136.             Cycles+=2;
  137.             return;
  138.             }
  139.         }
  140.     else {
  141.         error("Unknown Addressing Mode");
  142.         return;
  143.         }
  144. }
  145.  
  146. /*
  147.  *      do_indexed --- handle all wierd stuff for indexed addressing
  148.  */
  149. do_indexed(op)
  150. int op;
  151. {
  152.     emit(op);
  153.     eval();
  154.     if( mapdn(*++Optr) != 'x' )
  155.         warn("Indexed Addressing Assumed");
  156.     if( Result < 0 || Result > 255)
  157.         warn("Value Truncated");
  158.     emit(lobyte(Result));
  159. }
  160.